import 'package:flutterclue/http_util/base_http.dart';
import 'package:flutterclue/mvp/mode/base_mode.dart';
import 'package:flutterclue/http_util/http_tools.dart';
import 'package:flutter/material.dart';

abstract class BaseView {
  showLoadingView();

  dismissLoadingView();
}

abstract class BasePresenter<T> {
  detachView();

  attachView(T page);
}

class ClueBasePresenter<T> extends BasePresenter<T> {
  T baseView;

  Future<BaseBean> postData(
      {String url,
      Map<String, Object> headers,
      Map<String, Object> params,
      ValueChanged<String> error}) {
    return HttpFactory.getHttpInstance(HttpUtilsByDio.initInstance())
        .postData(url: url, headers: headers, params: params, error: error);
  }

  checkView() {
    if (baseView == null) {
      throw new Exception("baseView can not null,请在使用presenter实例之前attachView");
    }
  }

  @override
  detachView() {
    baseView = null;
  }

  @override
  attachView(T page) {
    baseView = page;
  }
}
